package com.example.tool.erp.demo;

import com.example.tool.erp.sdk.Client;
import com.example.tool.erp.sdk.Pager;
import com.example.tool.erp.sdk.WdtErpException;
import com.example.tool.erp.sdk.api.sales.StockOutAPI;
import com.example.tool.erp.sdk.api.sales.dto.StockoutQueryHistoryRequest;
import com.example.tool.erp.sdk.api.sales.dto.StockoutQueryHistoryResponse;
import com.example.tool.erp.sdk.impl.ApiFactory;
import com.example.tool.erp.sdk.impl.DefaultClient;

public class SalesStockOut
{
	public static void main(String[] args) throws WdtErpException
	{
		Client client = DefaultClient.get("wdterp30", "http://172.172.1.62:30000/", "xyx_api",
				"e8866c1681dacc9488a19c89991791b8:8f5800dab84b7a8d614e92cba739032c");
		StockOutAPI stockOutAPI = ApiFactory.get(client, StockOutAPI.class);

		queryHistory(stockOutAPI);
	}

	private static void queryHistory(StockOutAPI api) throws WdtErpException
	{
		StockoutQueryHistoryRequest request = new StockoutQueryHistoryRequest();
		request.setStartTime("2022-07-02");
		request.setEndTime("2022-08-01");
		request.setNeedSn(1);

		StockoutQueryHistoryResponse response = api.queryHistory(request, new Pager(10, 0, true));

		if (response.getTotalCount() == null || response.getTotalCount() == 0)
		{
			System.out.println("No eligible results!");
			return;
		}

		System.out.println("total: " + response.getTotalCount());
		for (StockoutQueryHistoryResponse.Order order : response.getOrders())
		{
			System.out.print("tradeNo no:" + order.getTradeNo() + " modified : " + order.getModified());
		}
	}
}
